<template>
  <div>
    <el-button type="primary" @click="isVisible = true" icon="el-icon-circle-plus-outline">新增代理</el-button>
    <div class="table-body">
      <el-table :data="tableData" border size="medium" style="width: 100%">
        <el-table-column label="序号" prop="sort"></el-table-column>
        <el-table-column prop="name" label="代理名称"></el-table-column>
        <el-table-column prop="num" label="代理准入标准"></el-table-column>
        <el-table-column prop="rebateProportion" label="返现额度  %"></el-table-column>
        <!-- <el-table-column prop="autoUpdate" label="是否自动升级"></el-table-column> -->
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" size="mini">修改</el-button>
            <el-popconfirm title="确定删除此代理？" @onConfirm="handleConfirmDelete(scope.row)">
              <el-button style="margin-left:20px" size="mini" type="danger" slot="reference">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog title="新增代理" :visible.sync="isVisible" width="40%">
      <add-delegete @submit="submitevent" @cancel="isVisible = $event" />
    </el-dialog>
    <el-dialog title="修改代理" :visible.sync="isVisible1" width="40%">
      <updateDetagete @submit="updateEvent" :data="propdata" v-if="isVisible1" @cancel="isVisible1 = $event"/>
    </el-dialog>
  </div>
</template>

<script>
import AddDelegete from "./AddDelegete";
import updateDetagete from "./updateDelegete";
export default {
  data() {
    return {
      isVisible: false,
      isVisible1: false,
      tableData: [],
      propdata: {}
    };
  },
  mounted() {
    this.getAgentList();
  },
  methods: {
    getAgentList() {
      this.$service.delegeteList().then(res => {
        //console.log(res);
        this.tableData = res.data;
      });
    },
    handleConfirmDelete(data) {
      //console.log(data);
      this.$service.deleAgent(data.id).then(res => {
        this.$message({
          message: "删除成功",
          type: "success"
        });
        this.getAgentList();
      });
    },
    handleClick(row) {
      //console.log(row);
      this.propdata = row;
      this.isVisible1 = true;
    },
    submitevent() {
      this.isVisible = false;
      this.getAgentList();
    },
    updateEvent() {
      this.isVisible1 = false;
      this.getAgentList();
    }
  },
  components: {
    "add-delegete": AddDelegete,
    updateDetagete
  }
};
</script>

<style>
</style>